package com.ftg.learn.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

/**
 * 数据提供者
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/6/1 上午10:08
 */
@RestController
public class SendController {

    @Resource
    RabbitTemplate rabbitTemplate;

    @GetMapping("/send/{mess}")
    public String send(@PathVariable("mess") String mess) throws UnsupportedEncodingException {
        Message mess1 = new Message(mess.getBytes("utf-8"));
        rabbitTemplate.send("","hello",mess1);
        return "success";
    }

    /**
     * 就是我们的发布订阅者模式
     * @param mess 消息
     * @return success
     * @throws UnsupportedEncodingException
     */
    @GetMapping("/pubsubSend/{mess}")
    public String pubsubSend(@PathVariable("mess") String mess) throws UnsupportedEncodingException {
        Message mess1 = new Message(mess.getBytes("utf-8"));
        rabbitTemplate.send("telmess1","",mess1);
        return "success";
    }


}
